package com.jule.miaozhuapc.dao.impl;

import java.util.List;

import com.jule.miaozhuapc.domain.WawaPayConfig;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import com.jule.miaozhuapc.dao.PayConfigDao;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Repository
public class PayConfigDAOImpl  implements PayConfigDao{

	private EntityManager em;
	@PersistenceContext
	public void setEm(EntityManager em) {
		this.em = em;
	}

	@Override
	public WawaPayConfig findbyId(long id) {
		String hql = "from WawaPayConfig where id = ? and isDelete = 0 and now() BETWEEN startTime and endTime";

		WawaPayConfig payConfig = em.find(WawaPayConfig.class, id);
		return payConfig;
	}

	@Override
	public List<WawaPayConfig> findAll() {

		String hql = "from WawaPayConfig  where isDelete = 0 and now() BETWEEN startTime and endTime ORDER BY  seq DESC , addTime DESC";
		List<WawaPayConfig> wawaPayConfigs = em.createQuery(hql).getResultList();
		return wawaPayConfigs;
	}
}
